using System;
using System.Collections.Generic;
using System.Text;

namespace Coding
{
    public class IntConverter
    {
        public static byte[] ToBytes(int value)
        {
            byte[] result = new byte[4];

            result[0] = (byte)(value >> 24);
            result[1] = (byte)(value >> 16);
            result[2] = (byte)(value >> 8);
            result[3] = (byte) value;

            return result;
        }

        public static void ToBytes(int value, ref byte[] result, int start)
        {
            result[start] = (byte)(value >> 24);
            result[start + 1] = (byte)(value >> 16);
            result[start + 2] = (byte)(value >> 8);
            result[start + 3] = (byte) value;
        }


        public static int FromBytes(byte[] values)
        {
            int result = 0;
            result += values[0] << 24;
            result += values[1] << 16;
            result += values[2] << 8;
            result += values[3];

            return result;
        }

        public static int FromBytes(byte[] values, int start)
        {
            int result = 0;
            result += values[start] << 24;
            result += values[start + 1] << 16;
            result += values[start + 2] << 8;
            result += values[start + 3];

            return result;
        }
    }
}
